<%@ page import="com.zy.smbms.pojo.SmbmsUser" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    SmbmsUser user=(SmbmsUser)session.getAttribute("sessionUser");
    String passwords=user.getUserpassword();
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="<%=basePath%>css/public.css"/>
    <link rel="stylesheet" href="<%=basePath%>css/style.css"/>
</head>
<body>
<!--头部-->
    <header class="publicHeader">
        <h1>超市账单管理系统</h1>
        <div class="publicHeaderR">
            <p><span>下午好！</span><span style="color: #fff21b">${sessionScope.sessionUser.username}</span> , 欢迎你！</p>
            <a href="<%=basePath%>userController/login">退出</a>
        </div>
    </header>
<!--时间-->
    <section class="publicTime">
        <span id="time">2015年1月1日 11:11  星期一</span>
        <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
    </section>
<!--主体内容-->
    <section class="publicMian ">
        <div class="left">
            <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
            <nav>
                <ul class="list">
                    <li ><a href="<%=basePath%>billController/billlist">账单管理</a></li>
                    <li><a href="<%=basePath%>providerController/providerlist">供应商管理</a></li>
                    <li><a href="<%=basePath%>userController/userlist">用户管理</a></li>
                    <li id="active"><a href="<%=basePath%>userController/passwordPage">密码修改</a></li>
                    <li><a href="<%=basePath%>userController/login">退出系统</a></li>
                </ul>
            </nav>
        </div>
        <div class="right">
            <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>密码修改页面</span>
            </div>
            <div class="providerAdd">
                <form id="passwordUpdate">
                    <!--div的class 为error是验证错误，ok是验证成功-->
                    <div class="">
                        <label for="oldPassword">旧密码：</label>
                        <input type="password" name="oldPassword" id="oldPassword" required/>
                        <span>*请输入原密码</span>
                    </div>
                    <div>
                        <label for="newPassword">新密码：</label>
                        <input type="text" name="newPassword" id="newPassword" required/>
                        <span >*请输入新密码</span>
                    </div>
                    <div>
                        <label for="reNewPassword">确认新密码：</label>
                        <input type="text" name="reNewPassword" id="reNewPassword" required/>
                        <span >*请输入新确认密码，保证和新密码一致</span>
                    </div>
                    <div class="providerAddBtn">
                        <!--<a href="#">保存</a>-->
                        <a href="javascript:void(0)" onclick="updatePassword()">保存</a>
                    </div>
                </form>
            </div>
        </div>
    </section>
    <footer class="footer">
        版权归北大青鸟
    </footer>
<script src="<%=basePath%>js/jquery.js"></script>
<script src="<%=basePath%>js/js.js"></script>
<script src="<%=basePath%>js/time.js"></script>
<script type="text/javascript">
    function updatePassword() {
        const oldPassword = document.getElementById("oldPassword").value;
        const newPassword = document.getElementById("newPassword").value;
        const rePassword = document.getElementById("reNewPassword").value;
        if(newPassword===rePassword) {
            if($.trim(oldPassword)===$.trim(<%=passwords%>)) {
                $.post("<%=basePath%>userController/updatePassword", {
                    "password": newPassword
                }, function (data) {
                    if (data == "OK") {
                            alert("密码修改成功，请重新登录！");
                            window.location.href = "<%=basePath%>userController/login";
                        } else{
                            window.location.href = "<%=basePath%>userController/passwordPage";
                    }
                });
            }
            else
                $("#newPassword").val("密码输入错误！");
        }
        else
            $("#reNewPassword").val("两次输入的密码不一致，请重新输入！");
    }
</script>
</body>
</html>